<%@ tag language="java" pageEncoding="UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp" %>
<%@ attribute name="iconStyle" type="java.lang.String" required="false" description="按钮样式" %>
<%@ attribute name="title" type="java.lang.String" required="false" description="弹出框标题" %>
<%@ attribute name="mainIP" type="java.lang.String" required="false" description="服务器IP" %>
<%@ attribute name="mainPort" type="java.lang.String" required="false" description="服务器IP" %>
<%@ attribute name="monitorPort" type="java.lang.String" required="false" description="服务器IP" %>
<%@ attribute name="vccID" type="java.lang.String" required="false" description="呼叫中心ID" %>
<%@ attribute name="sipPort" type="java.lang.String" required="false" description="端口" %>
<%@ attribute name="agentID" type="java.lang.String" required="false" description="坐席ID" %>
<%@ attribute name="dnHead" type="java.lang.String" required="false" description="坐席ID" %>
<%@ attribute name="agentHead" type="java.lang.String" required="false" description="坐席ID" %>
<%@ attribute name="isInit" type="java.lang.String" required="false" description="初始化直接显示" %>
<%@ attribute name="isDebugger" type="java.lang.String" required="false" description="是否为编译模式" %>
<%@ attribute name="autoRun" type="java.lang.String" required="false" description="自动加载" %>
<%@ attribute name="clickLoad" type="java.lang.String" required="false" description="点击则加载" %>

<style>
    /** 电话键盘 **/
    .dial {
        width: 52px;
        height: 30px;
        font-size: 20px;
        line-height: 20px;
        font-weight: bold;
    }

    .dial-table {
        width: 100%;
    }

    .dial-table tr td {
        padding: 0px;
    }

    .dial-table tr td button {
        width: 52px;
        height: 30px;
        font-size: 12px;
        line-height: 20px;
        font-weight: bold;
    }
</style>

<c:if test="${empty title}">
    <c:set value="jvcc电话条" var="title"/>
</c:if>
<!--设置初始值-->
<%--<c:set value="202.173.9.105" var="mainIP"/>--%>
<%--<c:set value="100000" var="vccID"/>--%>
<%--<c:set value="14800" var="mainPort"/>--%>
<%--<c:set value="14850" var="monitorPort"/>--%>
<%--<c:set value="5030" var="sipPort"/>--%>
<%--<c:set value="000002" var="dnHead"/>--%>
<%--<c:set value="000010" var="agentHead"/>--%>
<%--<c:set value="${fns:getUser().no}" var="agentID"/>--%>
<c:set value="${dnHead}${vccID}${agentID}" var="fullAgentID"/>

<link rel="stylesheet" type="text/css" href="${ctxStatic}/jvcc/css/phone-icon.css">
<li>
    <a href="javascript:void(0);" id="phoneBar" style="color: #808080;text-shadow:#000 1px 1px 1px;" title="">
        <i class="fa-phone" style="font-size:15px;${iconStyle}"></i>
    </a>
</li>
<div id="barContent" style="display: none;">
    <div id="mainPhone" style="padding-top: 0px;">
        <button class="btn-phone" id="phone-sm">
            <i class="phone-sm"></i>
            <br>
            示忙
        </button>
        <button class="btn-phone" id="phone-sx">
            <i class="phone-sx"></i>
            <br>
            示闲
        </button>
        <button class="btn-phone" id="phone-hc">
            <i class="phone-hc"></i>
            <br>
            呼出
        </button>
        <button class="btn-phone" id="phone-bc">
            <i class="phone-bc"></i>
            <br>
            保持
        </button>
        <button class="btn-phone" id="phone-jh">
            <i class="phone-jh"></i>
            <br>
            接回
        </button>
        <button class="btn-phone" id="phone-gd">
            <i class="phone-gd"></i>
            <br>
            挂断
        </button>
        <button class="btn-phone" id="phone-zy">
            <i class="phone-zy"></i>
            <br>
            转移
        </button>
        <button class="btn-phone" id="phone-hy">
            <i class="phone-hy"></i>
            <br>
            会议
        </button>
        <button class="btn-phone" id="phone-yd">
            <i class="phone-yd"></i>
            <br>
            应答
        </button>
        <button class="btn-phone" id="phone-zc">
            <i class="phone-zc"></i>
            <br>
            转出
        </button>
        <button class="btn-phone" id="phone-zx">
            <i class="phone-zx"></i>
            <br>
            咨询
        </button>
        <button class="btn-phone" id="phone-zb">
            <i class="phone-zb"></i>
            <br>
            再拨
        </button>
        <button class="btn-phone" id="phone-qj">
            <i class="phone-qj"></i>
            <br>
            桥接
        </button>
        <button class="btn-phone" id="phone-config" date-state="0">
            <i class="phone-sz"></i>
            <br>
            <span>加载</span>
        </button>
        <button class="btn-phone" id="phone-reset" date-state="0">
            <i class="phone-fw"></i>
            <br>
            <span>复位</span>
        </button>
    </div>
    <div id="phoneLoggerBar">
        <textarea id="phoneLogger" readonly="readonly" class="phones-log"></textarea>
        <button class="btn btn-info" onclick="clearLog()">
            清除
        </button>
        <a href="#dial" role="button" class="btn btn-info" data-toggle="modal">表盘1</a>
        <a href="#trans" role="button" class="btn btn-info" data-toggle="modal">表盘2</a>
        <a href="#consult" role="button" class="btn btn-info" data-toggle="modal">表盘3</a>
    </div>
</div>
<!--呼出拨号盘-->
<div id="dial" style="max-width: 220px;width: 220px;margin-left: -110px;" class="modal hide fade" tabindex="-1"
     role="dialog" aria-hidden="true">
    <div class="modal-header" style="padding: 3px 15px;">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
        <h5>呼出<span id="dial-title"></span></h5>
    </div>
    <div class="modal-body" style="text-align: center;">
        <div>
            <div class="input-prepend">
                <span class="add-on">选&nbsp;择</span>
                <select id="dial-type" class="select-small">
                    <option value="out" selected="selected">&nbsp;外&nbsp;&nbsp;呼&nbsp;</option>
                    <option value="in">&nbsp;内&nbsp;&nbsp;呼&nbsp;</option>
                    <option value="server">服务号码</option>
                </select>
            </div>
            <div class="input-prepend">
                <span class="add-on">号&nbsp;码</span>
                <input id="dial-phone-number" class="input-small" type="text" placeholder="请输入号码"/>
            </div>
        </div>
        <br>
        <div id="dial-number">
            <button class="btn btn-primary dial">1</button>
            &nbsp;
            <button class="btn btn-primary dial">2</button>
            &nbsp;
            <button class="btn btn-primary dial">3</button>
            <br>
            <button class="btn btn-primary dial">4</button>
            &nbsp;
            <button class="btn btn-primary dial">5</button>
            &nbsp;
            <button class="btn btn-primary dial">6</button>
            <br>
            <button class="btn btn-primary dial">7</button>
            &nbsp;
            <button class="btn btn-primary dial">8</button>
            &nbsp;
            <button class="btn btn-primary dial">9</button>
            <br>
            <button class="btn btn-primary dial">*</button>
            &nbsp;
            <button class="btn btn-primary dial">0</button>
            &nbsp;
            <button class="btn btn-primary dial">#</button>
        </div>
        <!--呼叫按钮盘-->
        <table id="dial-button" class="dial-table">
            <tr>
                <td>
                    <button class="btn btn-primary dial-btn" id="phone-dial-hc">呼叫</button>
                </td>
                <td rowspan="2">
                    <button class="btn btn-primary dial-btn" id="phone-dial-gd" style="height: 52px;width: 52px;">挂断
                    </button>
                </td>
                <td>
                    <button class="btn btn-primary" id="phone-dial-clear">清空</button>
                </td>
            </tr>
            <tr>
                <td>
                    <button class="btn btn-primary dial-btn" id="phone-dial-zb">再拨</button>
                </td>
                <td>
                    <button class="btn btn-primary" data-dismiss="modal" aria-hidden="true">关闭</button>
                </td>
            </tr>
        </table>
    </div>
</div>

<!--转移拨号盘-->
<div id="trans" style="max-width: 220px;width: 220px;margin-left: -110px;" class="modal hide fade" tabindex="-1"
     role="dialog" aria-hidden="true">
    <div class="modal-header" style="padding: 3px 15px;">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
        <h5>呼叫转出<span id="trans-title"></span></h5>
    </div>
    <div class="modal-body" style="text-align: center;">
        <div>
            <div class="input-prepend">
                <span class="add-on">选&nbsp;择</span>
                <select id="trans-type" class="select-small">
                    <option value="in" selected="selected">坐席工号</option>
                    <option value="out">外部号码</option>
                    <option value="server">服务号码</option>
                </select>
            </div>
            <div class="input-prepend">
                <span class="add-on">号&nbsp;码</span>
                <input id="trans-phone-number" class="input-small" type="text" placeholder="请输入号码"/>
            </div>
        </div>
        <br>
        <div id="trans-number">
            <button class="btn btn-primary dial">1</button>
            &nbsp;
            <button class="btn btn-primary dial">2</button>
            &nbsp;
            <button class="btn btn-primary dial">3</button>
            <br>
            <button class="btn btn-primary dial">4</button>
            &nbsp;
            <button class="btn btn-primary dial">5</button>
            &nbsp;
            <button class="btn btn-primary dial">6</button>
            <br>
            <button class="btn btn-primary dial">7</button>
            &nbsp;
            <button class="btn btn-primary dial">8</button>
            &nbsp;
            <button class="btn btn-primary dial">9</button>
            <br>
            <button class="btn btn-primary dial">*</button>
            &nbsp;
            <button class="btn btn-primary dial">0</button>
            &nbsp;
            <button class="btn btn-primary dial">#</button>
        </div>
        <!--转出按钮盘-->
        <table id="trans-button" class="dial-table">
            <tr>
                <td>
                    <button id="phone-dial-zc" class="btn btn-primary dial-btn" style="height: 52px;width: 52px;">转出</button>
                </td>
                <td>
                    <button class="btn btn-primary" style="height: 52px;width: 52px;" data-dismiss="modal" aria-hidden="true">关闭</button>
                </td>
            </tr>
        </table>
    </div>
</div>

<!--咨询拨号盘-->
<div id="consult" style="max-width: 220px;width: 220px;margin-left: -110px;" class="modal hide fade" tabindex="-1"
     role="dialog" aria-hidden="true">
    <div class="modal-header" style="padding: 3px 15px;">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
        <h5>咨询<span id="consult-title"></span></h5>
    </div>
    <div class="modal-body" style="text-align: center;">
        <div>
            <div class="input-prepend">
                <span class="add-on">选&nbsp;择</span>
                <select id="consult-type" class="select-small">
                    <option value="in" selected="selected">坐席工号</option>
                    <option value="out">外部号码</option>
                    <option value="server">服务号码</option>
                </select>
            </div>
            <div class="input-prepend">
                <span class="add-on">号&nbsp;码</span>
                <input id="consult-phone-number" class="input-small" type="text" placeholder="请输入号码"/>
            </div>
        </div>
        <br>
        <div id="consult-number">
            <button class="btn btn-primary dial">1</button>
            &nbsp;
            <button class="btn btn-primary dial">2</button>
            &nbsp;
            <button class="btn btn-primary dial">3</button>
            <br>
            <button class="btn btn-primary dial">4</button>
            &nbsp;
            <button class="btn btn-primary dial">5</button>
            &nbsp;
            <button class="btn btn-primary dial">6</button>
            <br>
            <button class="btn btn-primary dial">7</button>
            &nbsp;
            <button class="btn btn-primary dial">8</button>
            &nbsp;
            <button class="btn btn-primary dial">9</button>
            <br>
            <button class="btn btn-primary dial">*</button>
            &nbsp;
            <button class="btn btn-primary dial">0</button>
            &nbsp;
            <button class="btn btn-primary dial">#</button>
        </div>
        <!--咨询按钮盘-->
        <table id="consult-button" class="dial-table">
            <tr>
                <td>
                    <button class="btn btn-primary dial-btn" id="phone-dial-zx">咨询</button>
                </td>
                <td>
                    <button class="btn btn-primary dial-btn" id="phone-dial-gd1">挂断</button>
                </td>
                <td>
                    <button class="btn btn-primary dial-btn" id="phone-dial-zy">转移</button>
                </td>
            </tr>
            <tr>
                <td>
                    <button class="btn btn-primary dial-btn" id="phone-dial-hy">会议</button>
                </td>
                <td>
                    <button class="btn btn-primary dial-btn" id="phone-dial-zb1">再拨</button>
                </td>
                <td>
                    <button class="btn btn-primary" data-dismiss="modal" aria-hidden="true">关闭</button>
                </td>
            </tr>
        </table>
    </div>
</div>


<script src="${ctxStatic}/jvcc/japp.js" type="text/javascript"></script>
<script type="text/javascript" src="${ctxStatic}/jvcc/phone.js"></script>
<script type="text/javascript" language="javascript">
    var forceRefresh = false;
    ///参考bar中的完全调用方法
    window.onload = function () {
        applicationLoad(0, 0, 0, 0, showStyleNONE, "${ctxStatic}/", function () {
            OnAfterVccBarCreate();
            $("#phoneBar").css("color","#ffffff")
            if (IsWebSocketValid()) {
                if ("${autoRun}" != "false") {//自动加载
                    funInitial('${mainIP}', '${mainPort}',
                               '${monitorPort}', '${sipPort}',
                               '${vccID}', '${agentID}', '${dnHead}', '${agentHead}');
                } else {
                    $("#phone-config").phoneEnable();
                }
            } else {
                showTitle("当前浏览器不支持websocket请更换firefox 或 ie10以上!");
            }
        });
    };
    window.onbeforeunload = function (e) {
        loading("刷新页面将导致电话条重新加载,若无法连接电话条,请咨询开发或使用jvccbar.bat进行修复");
        applicationUnLoad();
    };
    window.onunload = function () {//此处重复调用为了防止未关闭的情况发生
        applicationUnLoad();
    };
    //电话条页面工具加载
    $(function () {
        //呼出破号盘
        $("#dial-phone-number").dropDownSelect({});
        $('#dial').on("hidden",function(){
            $("#phone-hc").phoneEnable();
        });
        $('#dial').on("shown",function(){
            $("#dial-phone-number").focus();
        });
        $("#dial-button .dial-btn").phoneDisable(); //禁用面板中按钮

        $("#dial-number .btn").click(function () { //数字按键
            var _this = $(this);
            var phone_number = $("#dial-phone-number");
            var phone_number_code = phone_number.val() + _this.text();
            phone_number.val(phone_number_code);
            phone_number.attr("data-phone-number",phone_number_code);
            phone_number.focus();
        });

        $("#phone-dial-clear").click(function () { //清除按键
            $("#dial-phone-number").val("");
        });
        $("#dial-type").on("change",function(){
            $("#dial-phone-number").clearPhoneNumber();
            var _val = $(this).val();
            if(_val=="in"){//若为内呼
                $("#dial-phone-number").dropDownSelect("recoverList","in");
            }
            if(_val=="out"){//若为外呼
                $("#dial-phone-number").dropDownSelect("recoverList","out");
            }
            if(_val=="server"){//若为外呼
                application.oJVccBar.QuerySPGroupList(null,2,8,1);
            }
        });

        //转出拨号盘
        $("#trans-phone-number").dropDownSelect({});
        $('#trans').on("shown",function(){
            $("#trans-phone-number").focus();
        });
        $("#trans-button .dial-btn").phoneDisable(); //禁用面板中按钮
        $("#trans-number .btn").click(function () { //数字按键
            var _this = $(this);
            var phone_number = $("#trans-phone-number");
            var phone_number_code = phone_number.val() + _this.text();
            phone_number.val(phone_number_code);
            phone_number.attr("data-phone-number",phone_number_code);
            phone_number.focus();
        });

        $("#trans-type").on("change",function(){
            $("#trans-phone-number").clearPhoneNumber();
            var _val = $(this).val();
            if(_val=="in"){//若为内呼
                //application.oJVccBar.QuerySPGroupList(null,2,8,1);
                $("#trans-phone-number").dropDownSelect("recoverList","in");
            }
            if(_val=="out"){//若为内呼
                $("#trans-phone-number").dropDownSelect("recoverList","out");
            }
            if(_val=="server"){//若为服务
                application.oJVccBar.QuerySPGroupList(null,2,8,1);
            }
        });
        //咨询拨号盘consult
        $("#consult-phone-number").dropDownSelect({});
        $('#consult').on("shown",function(){
            $("#consult-phone-number").focus();
        });
        $("#consult-button .dial-btn").phoneDisable(); //禁用面板中按钮
        $("#consult-number .btn").click(function () { //数字按键
            var _this = $(this);
            var phone_number = $("#consult-phone-number");
            var phone_number_code = phone_number.val() + _this.text();
            phone_number.val(phone_number_code);
            phone_number.attr("data-phone-number",phone_number_code);
            phone_number.focus();
        });

        $("#consult-type").on("change",function(){
            $("#trans-phone-number").clearPhoneNumber();
            var _val = $(this).val();
            if(_val=="in"){//若为内呼
                //application.oJVccBar.QuerySPGroupList(null,2,8,1);
                $("#consult-phone-number").dropDownSelect("recoverList","in");
            }
            if(_val=="out"){//若外呼
                $("#consult-phone-number").dropDownSelect("recoverList","out");
            }
            if(_val=="server"){//若为服务
                application.oJVccBar.QuerySPGroupList(null,2,8,1);
            }
        });


        var btnControl = new BtnControl();
        btnControl.put("1", $("#phone-sm"));
        btnControl.put("2", $("#phone-sx"));
        btnControl.put("3", [$("#phone-dial-hc"), $("#phone-hc")]);
        btnControl.put("4", $("#phone-bc"));
        btnControl.put("5", $("#phone-jh"));
        btnControl.put("6", [$("#phone-dial-gd"), $("#phone-gd"),$("#phone-dial-gd1")]);
        btnControl.put("7", [$("#phone-zy"),$("#phone-dial-zy")]);
        btnControl.put("8", [$("#phone-hy"),$("#phone-dial-hy")]);
        btnControl.put("9", $("#phone-yd"));
        btnControl.put("10", [$("#phone-zc"),$("#phone-dial-zc")]);
        btnControl.put("11", [$("#phone-zx"),$("#phone-dial-zx")]);
        btnControl.put("12", [$("#phone-dial-zb1"),$("#phone-dial-zb"), $("#phone-zb")]);
        btnControl.put("13", $("#phone-qj"));
        btnControl.put("16", $("#phone-reset"));
        $("#mainPhone .btn-phone").phoneDisable(); //禁用全部按钮
        var options = {
            animation: true,
            html: true,
            content: $("#barContent"),
            phoneSuccess: function () {//成功初始化函数
                application.oJVccBar.succeeded = true;
                $("#phone-config").attr("date-state", 1).phoneEnable();
                $("#phone-config span").text("关闭");
                $("#phoneBar").css("color","lawngreen");
            },
            phoneExit: function () {//关闭加载按钮
                application.oJVccBar.succeeded = false;
                $("#mainPhone .btn-phone").phoneDisable(); //禁用全部按钮
                over_phone_config = $("#phone-config");
                setTimeout(function(){
                    over_phone_config.attr("date-state", 0).phoneEnable();
                    $(over_phone_config).find("span").text("加载");
                    $("#phoneBar").removeAttr("style");
                },3000);//延时设置加载按钮
            },
            phoneCallRing: function (CallingNo, CalledNo, OrgCalledNo) {//坐席呼出

            },
            phoneAnswerCall: function (AnswerTime, UserNo) {//电话接听

            },
            phoneCallEnd: function (param) {//坐席挂机
                var userParam = param.userParam;
                var fileName = param.fileName;
                if(!fileName){
                    //("没接通");
                    return;
                }
                if(!userParam){
                    //alert("不是通过接口打的");
                    return;
                }
                var realParam = str2Obj(param.userParam);
                if(realParam.customerId){//若存在
                    var _bar = $("#phoneBar");
                    //alert("挂机方式:"+param.disconnectType);
                    $.ajax({
                       url: "${ctx}/customer/potentialCall/save",
                       type: "post",
                       data: {
                           callId: param.callID,
                           filePath: param.directory+"/"+param.fileName,
                           potentialCustomerId: realParam.customerId,
                           strEndDate: param.endTime,
                           strStartDate: param.bgnTime,
                           toPhone: param.userNo,
                           serviceDirect: param.serviceDirect,
                           alertTime:(param.serviceDirect=="3"||param.serviceDirect=="1")?param.userAlertTime:param.agentAlertTime,
                           disconnectType:param.disconnectType
                       },
                       dataType: "json",
                       success: function (data) {
                           if (data.state == true) {
                               showTip(data.message);
                               if(realParam.event=="true"){
                                   _bar.trigger("recordEvent");
                               }
                           }
                       },
                       error: function (data, state, error) {
                           alertx(data.responseText, null, '请求错误');
                       }
                   });
                }//否则为其他拨打 不记录
            },
            phoneReportBtnStatus: function (btnIds, state) {
                if (state == 3 && btnIds == "0|6|12|15|16") {
                    btnIds = "0|6|15|16";//修正接通情况下,再拨按钮的bug
                }
                btnControl.callBackAll(function (item) {
                    $(item).phoneDisable();
                });
                btnControl.callBackSplit(btnIds, function (item) {
                    $(item).phoneEnable();
                });

            },
            phoneRespose: function (cmdName, param) {
                switch (cmdName){
                    case "QuerySPGroupList":{
                        var array = new Array();
                        $.each(param.split("$"),function(){
                            if(this!=null&&""!=this){
                                var values = this.split("|");
                                array.push({value:values[1],text:values[2]});
                            }
                        });
                        if($("#dial-type").val()=="server"){
                            $("#dial-phone-number").dropDownSelect("addList",array,"server");
                        }
                        if($("#trans-type").val()=="server") {
                            $("#trans-phone-number").dropDownSelect("addList", array, "server");
                        }
                        if($("#consult-type").val()=="server") {
                            $("#consult-phone-number").dropDownSelect("addList", array, "server");
                        }

                        break;
                    }
                    case "CallIn":{
                        if(param!=0){
                            alertx("内呼失败:"+application.oJVccBar.oBarControl.GetErrorItemDes(param));
                        }
                        break;
                    }
                    case "TransferOut":{
                        if(param!=0){
                            alertx("转出失败:"+application.oJVccBar.oBarControl.GetErrorItemDes(param));
                        }
                        break;
                    }
                    case "ForceReset":{
                        application.oJVccBar.GetBtnStatus();
                        break;
                    }
                    case "GetBtnStatus":{
                        break;
                    }
                    default :{
                        if(param!=0){
                            alertx("电话条错误:"+application.oJVccBar.oBarControl.GetErrorItemDes(param));
                        }
                    }

                }

            },
            phoneAgentWorkReport: function (workStatus) {//呼出事件回报

            },
            phonePrompt: function (code) {
            }
        };
        $("#phoneBar").jvccBar(options); //配置
        //电话标签
        $("#phoneBar").click(function () {
            if(application!=null&&application.oJVccBar!=null){
                $(this).jvccBar('toggle');
                if(!application.oJVccBar.succeeded&&"${clickLoad eq 'true'}"){
                    /*funInitial('${mainIP}', '${mainPort}',
                               '${monitorPort}', '${sipPort}',
                               '${vccID}', '${agentID}', '${dnHead}', '${agentHead}');*/
                    $("#phone-config").trigger("click");
                    //application.inited = true;
                }
            }else{
                alertx("电话条并未初始化完毕!");
            }


        });
        //自动打开标签
        if ("${isInit}" != "false") {
            $("#phoneBar").jvccBar('show');
        }
        //自动调试框加载
        if ("${isDebugger}" != "true") {
            $("#phoneLoggerBar").hide();
        }
        /******************************************************************
         * 按钮控制部分
         * 控制说明:按钮分为两类,强制型按钮和回调型
         * 所谓强制如 强复位和配置等之类按钮,按下后必须禁止其可用状态,第一次调用失败则必然失败
         * 所谓回调如 挂断\呼叫等,若失败则可以继续,按钮禁止应放在回调中
         ******************************************************************/
            //配置按钮 (加载和断开)
        $("#phone-config").click(function () {
            var state = parseInt($("#phone-config").attr("date-state"));
            $("#mainPhone .btn-phone").phoneDisable();
            switch (state) {
                case 0:
                {
                    funInitial('${mainIP}', '${mainPort}',
                               '${monitorPort}', '${sipPort}',
                               '${vccID}', '${agentID}', '${dnHead}', '${agentHead}');
                }
                    break;
                case 1:
                {
                    application.oJVccBar.UnInitial();
                }
                    break;
            }
        });
        //示闲
        $("#phone-sx").click(function () {
            application.oJVccBar.SetIdle();
            //$(this).phoneDisable();
        });
        //示忙
        $("#phone-sm").click(function () {
            var busyTypes = application.oVccBarAssist.oBarAgentStatus._arrSubBusyText;
            var submit = function (code) {
                application.oJVccBar.SetBusy(code);
                return true;
            };
            var buttonCode = '({';
            $(busyTypes).each(function (i, item) {
                if (i != 0) {
                    buttonCode = buttonCode + '"' + item + '"' + ": " + i;
                    if ((i + 1) != busyTypes.length) {
                        buttonCode = buttonCode + ","
                    }
                }
            });
            buttonCode = buttonCode + "})";
            $.jBox.confirm("请选择示忙类型,点击X退出", "选择", submit, {buttons: eval(buttonCode)});
        });
        //强复位
        $("#phone-reset").click(function () {//
            //$("#mainPhone .btn-phone").phoneDisable();
            application.oJVccBar.FroceReset();
        });
        //打开拨号盘
        $("#phone-hc").click(function () {
            $('#dial').modal('show');
        });

        //呼出 (内呼外呼)
        $("#phone-dial-hc").click(function () {
            var phone_number = $("#dial-phone-number").getPhoneNumber();
            if (phone_number == null || "" == phone_number) {
                alertx("请输入电话号码!");
                return;
            }
            var _call_type = $("#dial-type").val();
            if (_call_type=="out") {
                //alert("假设拨打电话:"+phone_number);
                application.oJVccBar.MakeCall(phone_number, 2, phone_number);
                $("#dial-phone-number").dropDownSelect("addList",{value:phone_number,text:phone_number},"out");
            } else if(_call_type=="in"){
                //alert("假设内呼电话:"+phone_number);
                application.oJVccBar.CallIn(phone_number, 0);
                $("#dial-phone-number").dropDownSelect("addList",{value:phone_number,text:phone_number},"in");
            } else if(_call_type=="server"){
                application.oJVccBar.CallIn(phone_number, 0);
            }
        });

        //可用$("#phone-gd").add("#phone-dial-gd") 代替
        //挂断
        $("#phone-gd").click(function () {
            application.oJVccBar.Disconnect(0);//仅挂断当前
        });
        //挂断内部按钮
        $("#phone-dial-gd").click(function () {
            application.oJVccBar.Disconnect(0);//仅挂断当前
        });
        $("#phone-dial-gd1").click(function () {
            application.oJVccBar.Disconnect(0);//仅挂断当前
        });
        //再拨
        $("#phone-zb").click(function () {
            $('#dial').modal('show');
        });
        //再拨
        $("#phone-dial-zb").click(function () {
            var phone_number = $("#dial-phone-number").getPhoneNumber();
            if (phone_number != null && "" != phone_number) {
                application.oJVccBar.SendDTMF(phone_number);
            } else {
                alertx("输入再拨号码!");
                return;
            }
        });
        $("#phone-dial-zb1").click(function () {
            var phone_number = $("#consult-phone-number").getPhoneNumber();
            if (phone_number != null && "" != phone_number) {
                application.oJVccBar.SendDTMF(phone_number);
            } else {
                alertx("输入再拨号码!");
                return;
            }
        });
        //保持
        $("#phone-bc").click(function () {
            application.oJVccBar.Hold();
        });
        //接回
        $("#phone-jh").click(function () {
            application.oJVccBar.RetrieveHold();
        });
        //应答
        $("#phone-yd").click(function () {
            application.oJVccBar.Answer(1);
        });
        //打开转出拨号盘
        $("#phone-zc").click(function () {
            $('#trans').modal('show');
        });
        //转出
        $("#phone-dial-zc").click(function () {
            var phone_number = $("#trans-phone-number").getPhoneNumber();
            if (phone_number == null || "" == phone_number) {
                alertx("请输入电话号码!");
                return;
            }
            var _call_type = $("#trans-type").val();
            if (_call_type=="out") {
                application.oJVccBar.TransferOut(1,phone_number);
                $("#trans-phone-number").dropDownSelect("addList",{value:phone_number,text:phone_number},"out");
            } else if(_call_type=="in"){
                application.oJVccBar.TransferOut(0,phone_number);
                $("#trans-phone-number").dropDownSelect("addList",{value:phone_number,text:phone_number},"in");
            } else if(_call_type=="server"){
                application.oJVccBar.TransferOut(2,phone_number);
            }
        });

        //咨询
        $("#phone-zx").click(function () {
            $('#consult').modal('show');

            //alertx("咨询功能开发中~~~");
            /*var type = 0;//0:座席工号，1：外部号码，2：服务号
             var number = "10086";
             application.oJVccBar.Consult(type,number);*/
        });
        $("#phone-dial-zx").click(function () {
            var phone_number = $("#consult-phone-number").getPhoneNumber();
            if (phone_number == null || "" == phone_number) {
                alertx("请输入电话号码!");
                return;
            }
            var _call_type = $("#consult-type").val();
            if (_call_type=="out") {
                application.oJVccBar.Consult(1,phone_number);
                $("#consult-phone-number").dropDownSelect("addList",{value:phone_number,text:phone_number},"out");
            } else if(_call_type=="in"){
                application.oJVccBar.Consult(0,phone_number);
                $("#consult-phone-number").dropDownSelect("addList",{value:phone_number,text:phone_number},"in");
            } else if(_call_type=="server"){
                application.oJVccBar.Consult(2,phone_number);
            }
        });
        //转移
        $("#phone-dial-zy").click(function () {
            //转移在咨询之后才能调用
            //alertx("转移功能开发中~~~");
            application.oJVccBar.Transfer();
        });
        $("#phone-zy").click(function () {
            //转移在咨询之后才能调用
            //alertx("转移功能开发中~~~");
            application.oJVccBar.Transfer();
        });
        //会议
        $("#phone-hy").click(function () {
            //会议在咨询之后才能调用
            //alertx("会议功能开发中~~~");
            application.oJVccBar.Conference();
        });
        $("#phone-dial-hy").click(function () {
            //会议在咨询之后才能调用
            //alertx("会议功能开发中~~~");
            application.oJVccBar.Conference();
        });


    });
</script>

